from PyQt4.QtCore import *
from PyQt4.QtGui import *
from zmq import PULL

from zmqsocket import *

class Sink(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.setWindowTitle("Sink")

        QVBoxLayout(self)
        self.progress=QProgressBar(self)
        self.layout().addWidget(self.progress)

        self._started=False
        self._counter=0

        self.receiver=ZmqSocket(PULL, self)
        self.receiver.bind("tcp://*:5558")
        self.receiver.readyRead.connect(self.read)

    def read(self):
        s=self.receiver.recv()
        for _s in s:
            if (not self._started) and (_s!='0'):
                print "Failed to start"
                self.quit()
            else: self._started=True
            self.progress.setValue(self.progress.value()+1)
            #self._counter+=1
            #if self._counter%10==0: print self._counter

if __name__=="__main__":
    from sys import argv
    a=QApplication(argv)
    s=Sink()
    s.show()
    exit(a.exec_())
